package com.dgut.dao;

import com.dgut.domain.Customer;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CustomerDao {
    @Select("select * from customer")
    public List<Customer> findAllCustomer();

    @Select("select * from customer where user_id = #{uid}")
    public List<Customer> findCustomerByUid(int uid);

    @Select("select COUNT(*) from customer")
    public int customerNum();
    @Select("select * from customer order by id limit #{startIndex}, #{perPageSize}")
    public List<Customer> findAllByPage(int startIndex, int perPageSize);
    @Select("delete from customer where id=#{id}")
    public void deleteCustomer(int id);
    @Insert("insert into customer(name,user_id,create_id,industry,level,phone,mobile,address,createtime) values(#{name},#{user_id},#{create_id},#{industry},#{level},#{phone},#{mobile},#{address},#{createtime})")
public void insertCustomer(Customer customer);

    @Select("select * from customer where id = #{id}")
//    多表查询 多对一
//    @Results({
//            @Result(property = "id",column = "id",id = true),
//            @Result(property = "name",column = "name"),
//            @Result(property = "user_id",column = "user_id"),
//            @Result(property = "create_id",column = "create_id"),
//            @Result(property = "industry",column = "industry"),
//            @Result(property = "level",column = "level"),
//            @Result(property = "phone",column = "phone"),
//            @Result(property = "mobile",column = "mobile"),
//            @Result(property = "address",column = "address"),
//            @Result(property = "createtime",column = "createtime"),
//            @Result(property = "user",one = @One(select = "com.dgut.dao.UserDao.findUserById",fetchType = FetchType.LAZY),column = "user_id"),
//            @Result(property = "creatUser",one = @One(select = "com.dgut.dao.UserDao.findUserById",fetchType = FetchType.LAZY),column = "create_id")
//    })
    public Customer getCustomerById(int id);

    @Update("update customer set user_id=#{user_id},industry=#{industry},level=#{level},phone=#{phone},mobile=#{mobile},address=#{address} where id=#{id}")
    public void updateCustomer(Customer customer);
    @SelectProvider(type = com.dgut.dao.CustomerDynaSQL.class,method = "selectCustomer")
    public List<Customer> selectCustomerByPara(Customer customer);


}
